import { AxiosError, AxiosRequestConfig, AxiosResponse } from '../types'

class AxiosErr extends Error implements AxiosError {
  isAxiosError: boolean
  config: AxiosRequestConfig
  code?: string | null
  request?: XMLHttpRequest
  response?: AxiosResponse
  constructor(message: string, config: AxiosError) {
    super(message)
    this.config = config.config
    this.code = config.code || null
    this.request = config.request
    this.response = config.response
    this.isAxiosError = true
    Object.setPrototypeOf(this, AxiosErr.prototype)
  }
}

export function createAxiosError(message: string, config: AxiosError) {
  const err = new AxiosErr(message, config)
  return err
}
